
APP.controller('example2', ["$http", "$scope", "$location", "$rootScope", function (http, scope, location, rootScope) {

    //加载数据
    http.get("yonghulist").success(function (response) {
        scope.data = response.data;
    });

    scope.goto = function () {
        location.path("example2_1/-1");
    }
    
    scope.update = function (yonghu) {
        location.path("example2_1/" + yonghu.yonghuid);
    }

    scope.del = function (yonghu) {
        http.get("yonghuinfodelete?yonghuid=" + yonghu.yonghuid).success(function (response) {            
            window.location.reload();
        });
    }
}]);

APP.controller('example2_1', ["$http", "$scope", "$location", "$rootScope", "$routeParams", function (http, scope, location, rootScope, params) {

    if (params.yonghuid > -1) {
        //加载数据
        http.get("yonghuinfo?yonghuid=" + params.yonghuid).success(function (response) {
            scope.yonghu = response.data;
        });
    }

    scope.back = function () {
        location.path("example2");
    }

    scope.save = function () {
        http.post('yonghuinfosave', scope.yonghu)
        .success(function (response) {
            location.path("example2");
        });
    }
}]);


APP.controller('example7', ["$http", "$scope", "$location", "$rootScope", "$routeParams", function (http, scope, location, rootScope, params) {
    scope.geta = function () {
        $.get('/example2/geta', { xingming: 'xingming1', nianling: 20 }, function (response) {
            alert(response.data);
        })
    }

    scope.posta = function () {
        $.post('/example2/posta', { xingming: 'xingming1', nianling: 20 }, function (response) {
            alert(response.data);
        })
    }
}]);

APP.controller('example5', ["$http", "$scope", "$location", "$rootScope", "$routeParams", function (http, scope, location, rootScope, params) {
    scope.model = function () {
        $.get('/example2/model', { xingming: '李晓伟', nianling: 20 }, function (response) {
            alert(response.data);
        })
    }

    
}]);

APP.controller('example8', ["$http", "$scope", "$location", "$rootScope", "$routeParams", function (http, scope, location, rootScope, params) {
    scope.trans = function () {
        $.get('/example2/testtrans', { xingming: 'xingming1', nianling: 20 }, function (response) {
            alert(response.data);
        })
    }

    scope.notrans = function () {
        $.post('/example2/testnotrans', { xingming: 'xingming1', nianling: 20 }, function (response) {
            alert(response.data);
        })
    }
}]);


APP.controller('example6', ["$http", "$scope", "$location", "$rootScope", "$routeParams", function (http, scope, location, rootScope, params) {
    /*
    参数：
     pageNo为页码
     itemsCount为记录的数量
     pageSize为每页显示数量
     */
    scope.pageing={
        pageNo : 1,
        itemsCount : 0,
        pageSize : 10
    };

    scope.list = function () {
        http.post("/example2/testpager", scope.pageing).success(function (response) {
            scope.data = response.data.list;
            scope.pageing = {
                pageNo: response.data.currentpage,
                itemsCount: response.data.recordcount,
                pageSize: response.data.pagesize
            };
        });
    };

    //执行分页
    scope.list();
}]);
